package homework_java.eg;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
class VIP implements Comparable{
	public String id, name;
	public String date1, date2;
	public String phone;public String level;	
	public VIP() {}
	public VIP(String id) {this.id = id;}
	public VIP(String id, String na, String da, String phone, String d2, String level) {
		this.id = id; this.name = na; this.date1 = da; this.phone = phone;this.date2 = d2;this.level = level;
	}
	public String toString() {
		return "[id = "+id+", name="+name+", bithdate="+date1+", indate="+date2+", phone="+phone+", level="+level+"]";
	}
	public boolean equals(Object obj) {
		VIP p = (VIP)obj;
		return new EqualsBuilder().append(this.id, p.id).isEquals();
	}
	public int hashCode() {
		return new HashCodeBuilder().append(this.id).toHashCode();	
	}
	public int compareTo(Object o) {
		return ((VIP)o).id.compareTo(this.id);
	}
}
class Gym{
	public ArrayList<VIP> VIPList = new ArrayList<VIP>();
	public boolean addVIP(VIP o) {
		if(VIPList.contains(o))
			return false;
		VIPList.add(o);
		return true;
	}
	public boolean removeVIP(VIP o) {
		if(!VIPList.contains(o)) //判断字符串是否有字串
			return false;
		VIPList.remove(o);		return true;		
	}
	public void display() {
		for(Iterator<VIP> it = VIPList.iterator(); it.hasNext();)
			System.out.println(it.next());
	}
	public void groupVIP() {
		ArrayList<VIP> list1 = new ArrayList<VIP>();//NORMAL
		ArrayList<VIP> list2 = new ArrayList<VIP>();//ADVANCED
		for(int i=0; i<VIPList.size(); i++ ) {
			VIP o = VIPList.get(i);
			if(o.level.equals("Normal")) 		list1.add(o);
			else		list2.add(o);				
		}
HashMap<String, ArrayList<VIP>> map = new HashMap<String, ArrayList<VIP>>();
		map.put("NORMAL", list1);		map.put("ADVANCED", list2);
		System.out.println(map);		
}

public static class Demo {
public static void main(String[] args) {
	Gym s = new Gym();
		s.addVIP(new VIP("001", "Ann","19880120","20180120", "13011111111","Normal"));
		s.addVIP(new VIP("001", "Jack","195980120","20160220", "13911119919","Normal"));
		s.addVIP(new VIP("002", "Anna","19970118","20120150", "15688888888","Advanced"));
		s.display();
		s.groupVIP();		s.display();
		s.removeVIP(new VIP("001"));		s.removeVIP(new VIP("000"));
		s.display();
		}
}
}